package vip.xiaonuo.bi.core.dataset.enums;

import cn.hutool.core.date.DateUtil;
import lombok.Getter;

import java.util.Arrays;
import java.util.List;

/**
 * 数据集-属性 改变可选类型 Long double Date String
 *   @author 顾育司
 *   @date  2023/12/29 12:09
 */
@Getter
public enum DataSetRowType {
    INT(){
        @Override
        public String converData(String value) {
            try {
                if(value.contains(".")){
                    return String.valueOf((int) Double.parseDouble(value));
                }
                return String.valueOf(Integer.parseInt(value));
            } catch (Exception e) {
                return null;
            }
        }
    },
    STRING(){
        @Override
        public String converData(String value) {
            return value;
        }
    },
    DOUBLE(){
        @Override
        public String converData(String value) {
            try {
                return String.valueOf(Double.parseDouble(value));
            } catch (Exception e) {
                return null;
            }
        }
    },
    DATE(){
        @Override
        public String converData(String value) {
            try {
                // 待测
                return   String.valueOf(DateUtil.format(DateUtil.parse(value), "yyyy/MM/dd"));
            } catch (Exception e) {
                return null;
            }
        }
    },
    TIMESTAMP(){
        @Override
        public String converData(String value) {
            try {
                return   String.valueOf(DateUtil.parse(value));
            } catch (Exception e) {
                return null;
            }
        }
    },
    BOOLEAN(){
        @Override
        public String converData(String dataset) {
            return dataset;
        }
    },
    LONG(){
        @Override
        public String converData(String value) {
            try {
             return    String.valueOf(Long.parseLong(value));
            } catch (Exception e) {
                return null;
            }
        }
    },
    SHORT(){
        @Override
        public String converData(String value) {
            try {
                if(value.contains(".")){
                    return String.valueOf((int) Double.parseDouble(value));
                }
                return String.valueOf(Integer.parseInt(value));
            } catch (Exception e) {
                return null;
            }
        }
    },
    FLOAT() {
        @Override
        public String converData(String value) {
            try {
                return String.valueOf(Float.parseFloat(value));
            } catch (Exception e) {
                return null;
            }
        }
    }
    ;

    public abstract String converData(String value);

    public static DataSetRowType getType(String type){
        return  valueOf(type.toUpperCase());
    }

    public static void main(String[] args) {
        // 测试
        List<String> doubleList = Arrays.asList("1.23", "4","659793", "ern","2017-01-01");

        doubleList.forEach(item->{DataSetRowType anInt = DataSetRowType.getType("double");
            System.out.println(anInt.converData(item));
        });
//        System.out.println(anInt.converData(doubleList));
    }
}
